using System;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.UI.Base;

namespace FireStarterModeller.UI.Relationship
{
    //TODO Brett 30 Jul 2009: This is currently not being used
    public class CreateRelationshipController : WizardController
    {
        private const int STEP_1 = 0;
//        private const int STEP_2 = 1;
//        private const int STEP_3 = 2;
//        private const int STEP_4 = 3;
        private readonly CreateRelationshipWizardStep1 _step1;
//        private readonly CreateRelationshipWizardStep2 _step1;
//        private readonly CreateRelationshipWizardStep3 _step3;
//        private readonly CreateRelationshipWizardStep4 _step4;
//        private readonly CreateRelationshipWizardStep5 _step5;
//        private DMRelationship _createdAssetType;
//        public event EventHandler<BOEventArgs<AssetType>> FireAssetTypeCreated;
//        private bool _fireAssetTypeSavedCalled;


        public CreateRelationshipController(DMClass dmClass)
        {
            _step1 = new CreateRelationshipWizardStep1(dmClass, GlobalUIRegistry.ControlFactory);
//            _step1 = new CreateRelationshipWizardStep2();
//            _step3 = new CreateRelationshipWizardStep3();
//            _step4 = new CreateRelationshipWizardStep4();
//            _step5 = new CreateRelationshipWizardStep5();
            AddStep(_step1);
//            AddStep(_step1);
//            AddStep(_step3);
//            AddStep(_step4);
//            AddStep(_step5);
        }

//        public AssetType CreatedAssetType
//        {
//            get { return _createdAssetType; }
//        }

        public override IWizardStep GetPreviousStep()
        {
//            if (CurrentStep == STEP_4)
//            {
//                if (_createdAssetType != null)
//                {
//                    _createdAssetType.AttributeGroups.CreatedBusinessObjects.Clear();
//                }
//            }
            return base.GetPreviousStep();
        }

        public override IWizardStep GetNextStep()
        {
            if (CurrentStep >= WizardSteps.Count - 1)
                throw new WizardStepException("Invalid Wizard Step: " + (CurrentStep + 1));

//            if (CurrentStep == STEP_1)
//            {
//                _createdAssetType = _step1.CreatedAssetType;
//
//                if (_step1.CreateAssetTypeManually)
//                {
//                    if (WizardSteps.Count == 5)
//                    {
//                        WizardSteps.RemoveAt(STEP_4);
//                        WizardSteps.RemoveAt(STEP_3);
//                        WizardSteps.RemoveAt(STEP_2);
//                    }
//                    _step5.CreatedAssetType = _createdAssetType;
//                    FireAssetTypeSaved();
//                }
//                else if (WizardSteps.Count != 5)
//                {
//                    WizardSteps.Insert(STEP_2, _step1);
//                    WizardSteps.Insert(STEP_3, _step3);
//                    WizardSteps.Insert(STEP_4, _step4);
//                }
//            }
//
//            if (CurrentStep == STEP_2)
//            {
//                _assetTypeToCopyFrom = _step1.SelectedAssetType;
//                _step3.AssetTypeToCopyFrom = _assetTypeToCopyFrom;
//            }
//            if (CurrentStep == STEP_3)
//            {
//                _createdAssetType.DeepCopySelectedAttributeGroups(_step3.SelectedAttibuteGroupCol);
//                _step4.CreatedAssetType = _createdAssetType;
//            }
//            if (CurrentStep == STEP_4)
//            {
//                _createdAssetType.Save();
//                _step5.CreatedAssetType = _createdAssetType;
//                FireAssetTypeSaved();
//            }
            return base.GetNextStep();
        }

//        private void FireAssetTypeSaved()
//        {
//            if ((FireAssetTypeCreated != null) && (_createdAssetType != null))
//            {
//                FireAssetTypeCreated(this, new BOEventArgs<AssetType>(_createdAssetType));
//            }
//            _fireAssetTypeSavedCalled = true;
//        }

//        public bool fireAssetTypeSavedCalled()
//        {
//            return _fireAssetTypeSavedCalled;
//        }
    }
}